/*********************************************************************************
  *FileName:  nsuc16xx_epwm.h
  *Version:   V1.0
  *Date:      2023-09-22
**********************************************************************************/

#ifndef  __nsuc16xx_epwm_H__
#define  __nsuc16xx_epwm_H__

/***************************************Includes***********************************/
#include "nsuc16x0.h"


/***************************************Macros***********************************/
#define EPWM_SlewRate_Normal												((uint8_t)0x00)
#define EPWM_SlewRate_Slow													((uint8_t)0x01)
#define EPWM_SlewRate_Fast													((uint8_t)0x02)
#define EPWM_SlewRate_VeryFast											((uint8_t)0x03)

#define EPWM_OC_FilterTime_2us4											((uint8_t)0x00)	/* 2.4us-2.8us */
#define EPWM_OC_FilterTime_4us8											((uint8_t)0x01)	/* 4.8us-5.6us */
#define EPWM_OC_FilterTime_9us6											((uint8_t)0x02)	/* 9.6us-11.2us */
#define EPWM_OC_FilterTime_19us2										((uint8_t)0x03)	/* 19.2us-22.4us */

#define EPWM_ClockSource_32M												((uint8_t)0x00)
#define EPWM_ClockSource_16M												((uint8_t)0x01)
#define EPWM_ClockSource_8M													((uint8_t)0x02)
#define EPWM_ClockSource_4M													((uint8_t)0x03)
#define EPWM_ClockSource_2M													((uint8_t)0x04)
#define EPWM_ClockSource_1M													((uint8_t)0x05)
#define EPWM_ClockSource_500K												((uint8_t)0x06)
#define EPWM_ClockSource_250K												((uint8_t)0x07)
#define EPWM_ClockSource_125K												((uint8_t)0x08)

#define EPWM_CCPT_62ns5															((uint8_t)0x00)
#define EPWM_CCPT_187ns5														((uint8_t)0x01)
#define EPWM_CCPT_375ns															((uint8_t)0x02)
#define EPWM_CCPT_625ns															((uint8_t)0x03)
#define EPWM_CCPT_812ns5														((uint8_t)0x04)
#define EPWM_CCPT_1000ns														((uint8_t)0x05)
#define EPWM_CCPT_1187ns5														((uint8_t)0x06)
#define EPWM_CCPT_1375ns														((uint8_t)0x07)
#define EPWM_CCPT_1625ns														((uint8_t)0x08)
#define EPWM_CCPT_1812ns5														((uint8_t)0x09)
#define EPWM_CCPT_2000ns														((uint8_t)0x0A)
#define EPWM_CCPT_2187ns5														((uint8_t)0x0B)
#define EPWM_CCPT_2375ns														((uint8_t)0x0C)
#define EPWM_CCPT_2625ns														((uint8_t)0x0D)
#define EPWM_CCPT_2812ns5														((uint8_t)0x0E)
#define EPWM_CCPT_3000ns														((uint8_t)0x0F)

#define EPWM_OCSDM_ALL															((uint8_t)0x00)
#define EPWM_OCSDM_OCOnly														((uint8_t)0x01)

#define EPWM_BridgeArm_Couple												((uint8_t)0x00) /* M0&M1 M2&M3 */
#define EPWM_BridgeArm_Single												((uint8_t)0x01) 

#define EPWM_Counter_CenterAlign										((uint8_t)0x00)
#define EPWM_Counter_EdgeAlign											((uint8_t)0x01)

#define EPWM_CLS_BEMFC_None													((uint8_t)0x00)
#define EPWM_CLS_BEMFC_CH0													((uint8_t)0x01)
#define EPWM_CLS_BEMFC_CH1													((uint8_t)0x02)
#define EPWM_CLS_BEMFC_CH2													((uint8_t)0x03)

#define EPWM_BridgeArm_OFF													((uint8_t)0x00)
#define EPWM_BridgeArm_ON														((uint8_t)0x01)
#define EPWM_BridgeArm_ReversePWM										((uint8_t)0x02)	/* Reverse PWM */
#define EPWM_BridgeArm_PWM													((uint8_t)0x03) 

#define EPWM_TrigState_Disable											((uint8_t)0x00) 
#define EPWM_TrigState_Enable												((uint8_t)0x01) 

#define EPWM_IT_EOP																	((uint32_t)0x01)
#define EPWM_IT_CMP																	((uint32_t)0x02)
#define EPWM_IT_CAP																	((uint32_t)0x04)
#define EPWM_IT_TRG																	((uint32_t)0x08)
#define EPWM_IT_OC																	((uint32_t)0x10)

/***************************************Variables***********************************/
typedef struct
{
    uint8_t EPWM_OFF_SlewRate;
    uint8_t EPWM_ON_SlewRate;
    uint8_t EPWM_OC_FilterTime;
    uint8_t EPWM_ClockSource;
    uint8_t EPWM_CC_ProtectionTime;
    uint8_t EPWM_OC_ShutDownMode;
    uint8_t EPWM_BridgeArmMode;
    uint8_t EPWM_CounterMode;

} EPWM_InitTypeDef;


typedef struct
{
    FunctionalState HalfBridge_CurrentLimit;
	uint8_t HalfBridge_CurrentLimitSource;
	uint8_t HalfBridge_LowSideOutMode;
	uint8_t HalfBridge_HighSideOutMode;
	uint16_t HalfBridge_Period;
	uint16_t HalfBridge_Compare;
} HalfBridge_InitTypeDef;

/***************************************Functions***********************************/
void EPWM_Init(EPWM_TypeDef* EPWMx, EPWM_InitTypeDef* EPWM_InitStruct);
void EPWM_Cmd(EPWM_TypeDef* EPWMx, FunctionalState NewState);
void EPWM_HalfBridge0_Init(EPWM_TypeDef* EPWMx, HalfBridge_InitTypeDef* HalfBridge_InitStruct);
void EPWM_HalfBridge1_Init(EPWM_TypeDef* EPWMx, HalfBridge_InitTypeDef* HalfBridge_InitStruct);
void EPWM_HalfBridge2_Init(EPWM_TypeDef* EPWMx, HalfBridge_InitTypeDef* HalfBridge_InitStruct);
void EPWM_HalfBridge3_Init(EPWM_TypeDef* EPWMx, HalfBridge_InitTypeDef* HalfBridge_InitStruct);	
void EPWM_HalfBridge0Config(EPWM_TypeDef* EPWMx, uint8_t LSOM, uint8_t HSOM);
void EPWM_HalfBridge1Config(EPWM_TypeDef* EPWMx, uint8_t LSOM, uint8_t HSOM);
void EPWM_HalfBridge2Config(EPWM_TypeDef* EPWMx, uint8_t LSOM, uint8_t HSOM);
void EPWM_HalfBridge3Config(EPWM_TypeDef* EPWMx, uint8_t LSOM, uint8_t HSOM);
void EPWM_SetCompare0(EPWM_TypeDef* EPWMx, uint16_t EPWM_Compare);
void EPWM_SetCompare1(EPWM_TypeDef* EPWMx, uint16_t EPWM_Compare);
void EPWM_SetCompare2(EPWM_TypeDef* EPWMx, uint16_t EPWM_Compare);
void EPWM_SetCompare3(EPWM_TypeDef* EPWMx, uint16_t EPWM_Compare);
void EPWM_Trig0ModeConfig(EPWM_TypeDef* EPWMx, uint8_t CounterUp_TrigState, uint8_t CounterDown_TrigState, uint8_t EPWM_TrigFilter);
void EPWM_Trig1ModeConfig(EPWM_TypeDef* EPWMx, uint8_t CounterUp_TrigState, uint8_t CounterDown_TrigState, uint8_t EPWM_TrigFilter);
void EPWM_Trig2ModeConfig(EPWM_TypeDef* EPWMx, uint8_t CounterUp_TrigState, uint8_t CounterDown_TrigState, uint8_t EPWM_TrigFilter);
void EPWM_Trig3ModeConfig(EPWM_TypeDef* EPWMx, uint8_t CounterUp_TrigState, uint8_t CounterDown_TrigState, uint8_t EPWM_TrigFilter);
void EPWM_Trig0TimeConfig(EPWM_TypeDef* EPWMx, uint16_t EPWM_TrigTime);
void EPWM_Trig1TimeConfig(EPWM_TypeDef* EPWMx, uint16_t EPWM_TrigTime);
void EPWM_Trig2TimeConfig(EPWM_TypeDef* EPWMx, uint16_t EPWM_TrigTime);
void EPWM_Trig3TimeConfig(EPWM_TypeDef* EPWMx, uint16_t EPWM_TrigTime);
void EPWM_MinimumOnTime0Cmd(EPWM_TypeDef* EPWMx, FunctionalState NewState);
void EPWM_MinimumOnTime1Cmd(EPWM_TypeDef* EPWMx, FunctionalState NewState);
void EPWM_MinimumOnTime2Cmd(EPWM_TypeDef* EPWMx, FunctionalState NewState);
void EPWM_MinimumOnTime3Cmd(EPWM_TypeDef* EPWMx, FunctionalState NewState);
void EPWM_MinimumOnTimeConfig(EPWM_TypeDef* EPWMx, uint16_t MinimumOnTime);
FlagStatus EPWM_GetOC0tatus(EPWM_TypeDef *EPWMx);
FlagStatus EPWM_GetOC1tatus(EPWM_TypeDef *EPWMx);
FlagStatus EPWM_GetOC2tatus(EPWM_TypeDef *EPWMx);
FlagStatus EPWM_GetOC3tatus(EPWM_TypeDef *EPWMx);
void EPWM_IT0Config(EPWM_TypeDef *EPWMx, uint32_t EPWM_IT, FunctionalState NewState);
void EPWM_IT1Config(EPWM_TypeDef *EPWMx, uint32_t EPWM_IT, FunctionalState NewState);
void EPWM_IT2Config(EPWM_TypeDef *EPWMx, uint32_t EPWM_IT, FunctionalState NewState);
void EPWM_IT3Config(EPWM_TypeDef *EPWMx, uint32_t EPWM_IT, FunctionalState NewState);

#endif
/* [] END OF nsuc16xx_epwm.h */
